//
//  HMSportSportingViewController.m
//  黑马行
//
//  Created by 宇宙执政 on 16/9/19.
//  Copyright © 2016年 yujianbinMAC. All rights reserved.
//

#import "HMSportSportingViewController.h"
#import "HMSportMapViewController.h"

@interface HMSportSportingViewController ()
@property (weak, nonatomic) IBOutlet UIButton *mapButton;

@property(nonatomic, strong)HMSportMapViewController *mapViewController;



@end

@implementation HMSportSportingViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupMapViewController];
}

-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    
    // 设置罗盘位置
    CGFloat x = _mapButton.center.x - _mapViewController.mapView.compassSize.width * 0.5;
    CGFloat y = _mapButton.center.y - _mapViewController.mapView.compassSize.height * 0.5;
    
    NSLog(@"mapButton.x = %f",_mapButton.center.x);
    NSLog(@"mapButton.y = %f",_mapButton.center.y);

    NSLog(@"compassSize= %f",_mapViewController.mapView.compassSize.width * 0.5);
    NSLog(@"compassSize = %f",_mapViewController.mapView.compassSize.height * 0.5);
    
    NSLog(@"x = %f",x);
    NSLog(@"y = %f",y);
    
    _mapViewController.mapView.compassOrigin = CGPointMake(x, y);
    
//    CGFloat xx = _mapButton.center.x - 18;
//    CGFloat yy = _mapButton.center.y - 18;
//    
//    _mapViewController.mapView.compassOrigin = CGPointMake(xx, yy);

}


-(void)setupMapViewController{
    
    //1，根据storyboard实例化地图控制器
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"HMSportSporting" bundle:nil];
    
    HMSportMapViewController *mapViewVC = [storyBoard instantiateViewControllerWithIdentifier:@"sportMapViewController"];
    
    //2，设置运动轨迹模型
    mapViewVC.sportTracking = [[HMSportTracking alloc] initWithType:_sportType state:HMSportStateContinue];
    
    //3，记录地图控制器
    _mapViewController = mapViewVC;
}


- (IBAction)changeStateAction:(UIButton *)sender {
    
    NSUInteger state = sender.tag;
    
    _mapViewController.sportTracking.sportState = state;
}


//
- (IBAction)openMapViewVCAction:(id)sender {
    
    //打开地图VC
    [self presentViewController:_mapViewController animated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
